package org.HU.train.business.controller.admin.fixed;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.HU.train.business.req.fixed.TrainQueryReq;
import org.HU.train.business.req.fixed.TrainSaveReq;
import org.HU.train.business.resp.fixed.TrainQueryResp;
import org.HU.train.business.service.fixed.TrainSeatService;
import org.HU.train.business.service.fixed.TrainService;
import org.HU.train.common.response.CommonResp;
import org.HU.train.common.response.PageResp;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/train")
public class TrainAdminController {

    @Resource
    private TrainService trainService;

    @Resource
    private TrainSeatService trainSeatService;

    /**
     * 保存车次信息
     */
    @PostMapping("/save")
    public CommonResp<Object> save(@Valid @RequestBody TrainSaveReq req) {
        trainService.save(req);
        return new CommonResp<>();
    }

    /**
     * 分页查询车次信息
     */
    @GetMapping("/query-list")
    public CommonResp<PageResp<TrainQueryResp>> queryList(@Valid TrainQueryReq req) {
        PageResp<TrainQueryResp> list = trainService.queryList(req);
        return new CommonResp<>(list);
    }

    /**
     * 删除某车次
     */
    @DeleteMapping("/delete/{id}")
    public CommonResp<Object> delete(@PathVariable Long id) {
        trainService.delete(id);
        return new CommonResp<>();
    }

    /**
     * 给火车--车站管理、火车--车厢管理时，新增相关信息时车次选择的下拉框使用
     */
    @GetMapping("/query-all")
    public CommonResp<List<TrainQueryResp>> queryList() {
        List<TrainQueryResp> list = trainService.queryAll();
        return new CommonResp<>(list);
    }

    /**
     * 一键生成某车次的座位信息
     */
    @GetMapping("/gen-seat/{trainCode}")
    public CommonResp<Object> genSeat(@PathVariable String trainCode) {
        trainSeatService.genTrainSeat(trainCode);
        return new CommonResp<>();
    }

}
